package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/a.html" )
public class AServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        resp.setCharacterEncoding("UTF-8");
        HttpSession session = req.getSession();
        String name= (String) session.getAttribute("user");
        System.out.println(name);
        resp.setContentType("text/html;charset=UTF-8");
        req.setAttribute("message","hello");
//        req.getRequestDispatcher("b.html").forward(req, resp);
//        resp.sendRedirect("b.html");
        resp.sendRedirect(req.getContextPath()+"/b.html");

//       PrintWriter out = resp.getWriter();
//        out.write("this is a");
//        out.flush();
//        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
